package com.example.designmode.strategyPattern;

//策略模式与简单工厂模式结合使用
public class Context {

    //组合抽象接口
    private Strategy strategy;
    //模式
    private String type;
    //单价
    private double unitPrice;
    //数量
    private double number;
    //满足满多少金额
    private double full;
    //减多少金额
    private double subtract;
    //折扣
    private double discount;

    /**
     * 通过全参构造 来创建出需要的算法
     * @param type 活动类型
     * @param unitPrice 单价
     * @param number 数量
     * @param full 满减条件
     * @param subtract 满减金额
     * @param discount 折扣
     */
    public Context(String type, double unitPrice, double number, double full, double subtract, double discount) {
        this.type = type;
        this.unitPrice = unitPrice;
        this.number = number;
        this.full = full;
        this.subtract = subtract;
        this.discount = discount;
        switch (type){
            case "折扣": this.strategy = new FormLoad(unitPrice,number,discount); break;
            case "满减": this.strategy = new FullSubtract(unitPrice,number,full,subtract); break;
            case "满减折扣": this.strategy = new FullSubtractFormLoad(unitPrice,number,full,subtract,discount); break;
        }
    }

    public double getResource(){
        return this.strategy.AlgorithmInterface();
    }
}
